package loop;

/**
 * @author:WIN10
 * @date:2022/1/15
 * @describe: 数组排序
 */
public class SortArray {

    public static void main(String[] args) {
        int[] array = {16, 9, 25, 23, 90};
        int n = array.length;
        System.out.println("排序前顺序：");
        for (int i = 0; i < n; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < n - 1 - i; j++) {
                //如果后面的数比前面的数大，进行交换
                if (array[j + 1] > array[j]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
        System.out.println("排序后顺序：");
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
    }
}
